package novel.common.utils.string;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringEscapeUtils;

/**
 * Created by 888 on 2017/2/20.
 */
public class StringUntils {
    public StringUntils()
    {
    }

    public static boolean isEmpty(String str){
        return str == null || str.isEmpty();
    }

    public static String collectionToStrings(Collection collection)
    {
        StringBuilder builder = new StringBuilder();
        if (collection != null && collection.size() > 0)
        {
            for (Iterator ite = collection.iterator(); ite.hasNext(); builder.append(","))
                builder.append(ite.next());

            builder.deleteCharAt(builder.length() - 1);
        }
        return builder.toString();
    }

    public static String makeStrCollection(List idList)
    {
        if (idList == null || idList.size() == 0)
            return "";
        StringBuilder builder = new StringBuilder();
        int i;
        for (i = 0; i < idList.size() - 1; i++)
            builder.append(idList.get(i)).append(",");

        builder.append(idList.get(i));
        return builder.toString();
    }

    public static String formateOrCondition(int num, String unit)
    {
        if (num <= 0)
            return "";
        StringBuilder builder = new StringBuilder(num * (unit.length() + 2));
        builder.append(unit);
        for (int i = 1; i < num; i++)
        {
            builder.append("or");
            builder.append(unit);
        }

        return builder.toString();
    }

    public static long transToLong(String input, String delim)
    {
        String tmpStr = input;
        long result = 0L;
        if (tmpStr == null || tmpStr.length() == 0)
            return result;
        String[] delimal = tmpStr.split(delim);
        if (delimal.length > 63)
            return result;
        int charInt = 0;
        for (int i = 0; i < delimal.length; i++)
        {
            try
            {
                charInt = Integer.parseInt(delimal[i]);
            }
            catch (Exception e)
            {
                charInt = 0;
            }
            if (charInt > 0)
                result += 1 << i;
        }

        return result;
    }

    public static String getPercent(double num, int fraction)
    {
        NumberFormat fmt = NumberFormat.getPercentInstance();
        fmt.setMaximumFractionDigits(fraction);
        return fmt.format(num);
    }

    public static String convNumber(double number, String formate)
    {
        DecimalFormat df = new DecimalFormat(formate);
        return df.format(number);
    }


    public static boolean isGBK(String input) throws UnsupportedEncodingException
    {
        return input.equals(new String(input.getBytes("GBK"), "GBK"));
    }



    private static boolean isNeedAlph(char c)
    {
        if (c >= 'a' && c <= 'z')
            return true;
        if (c >= 'A' && c <= 'Z')
            return true;
        if (c >= '0' && c <= '9')
            return true;
        if (c == '-')
            return true;
        return c == '_';
    }

    public static boolean isLatinCharacter(char c)
    {
        Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
        return Character.UnicodeBlock.BASIC_LATIN.equals(block);
    }

    public static String tokenizeListToStringNo(List input, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringBuffer result = new StringBuffer();
        for (Iterator inputIt = input.iterator(); inputIt.hasNext();)
        {
            String token = inputIt.next().toString();
            if (trimTokens)
                token = token.trim();
            if (!ignoreEmptyTokens || token.length() != 0)
            {
                result.append(token);
                result.append(delimiters);
            }
        }

        result.replace(result.length() - 1, result.length(), "");
        return result.toString();
    }


    public static String tokenizeListToStringNoEndSign(List input, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringBuffer result = new StringBuffer();
        for (Iterator inputIt = input.iterator(); inputIt.hasNext();)
        {
            String token = inputIt.next().toString();
            if (trimTokens)
                token = token.trim();
            if (!ignoreEmptyTokens || token.length() != 0)
            {
                result.append(token);
                if(inputIt.hasNext()){
                    result.append(delimiters);
                }

            }
        }

        //result.replace(result.length() - 1, result.length(), "");
        return result.toString();
    }

    public static String tokenizeStringToString(String[] s, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringBuffer result = new StringBuffer();
        if (delimiters == null)
            delimiters = ",";
        if (s != null && s.length > 0)
        {
            for (int i = 0; i < s.length; i++)
            {
                result.append(s[i]);
                result.append(delimiters);
            }

            result.replace(result.length() - delimiters.length(), result.length(), "");
        }
        return result.toString();
    }

    public static List<String> tokenizeStringToList(String s, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        List<String> tokens = new ArrayList<String>();
        if (s != null && s.length() > 0)
        {
            for (StringTokenizer st = new StringTokenizer(s, delimiters); st.hasMoreTokens();)
            {
                String token = st.nextToken();
                if (trimTokens)
                    token = token.trim();
                if (!ignoreEmptyTokens || token.length() != 0)
                    tokens.add(token);
            }

        }
        return tokens;
    }

    public static List<Long> tokenizeStringToListLong(String s, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        List <Long> tokens = new ArrayList <Long>();
        if (s != null && s.length() > 0)
        {
            for (StringTokenizer st = new StringTokenizer(s, delimiters); st.hasMoreTokens();)
            {
                String token = st.nextToken();
                if (trimTokens){
                    token = token.trim();
                }
                if(!isLong(token)){
                    continue;
                }
                if (!ignoreEmptyTokens || token.length() != 0)
                    tokens.add(Long.parseLong(token));
            }

        }
        return tokens;
    }

    public static String getPercent(double num)
    {
        NumberFormat fmt = NumberFormat.getPercentInstance();
        fmt.setMaximumFractionDigits(2);
        return fmt.format(num);
    }

    public static String getFractionDigits(double num, int fraction)
    {
        NumberFormat fmt = NumberFormat.getInstance();
        fmt.setMaximumFractionDigits(fraction);
        return fmt.format(num);
    }

    public static String getMoney(double num)
    {
        NumberFormat fmt = NumberFormat.getCurrencyInstance(Locale.CHINA);
        fmt.setMaximumFractionDigits(2);
        return fmt.format(num);
    }

    public static char getCharFromEnd(String inString, int index)
    {
        return inString.charAt(inString.length() - index - 1);
    }

    public static String replace(String inString, int index, char newChar)
    {
        if (inString == null)
            return null;
        int len = inString.length();
        if (index < 0 || index >= len)
        {
            return inString;
        } else
        {
            int pos = len - index - 1;
            StringBuffer sbuf = new StringBuffer();
            sbuf.append(inString, 0, pos);
            sbuf.append(newChar);
            sbuf.append(inString.substring(pos + 1));
            return sbuf.toString();
        }
    }

    public static String replace(String inString, String oldPattern, String newPattern)
    {
        if (inString == null)
            return null;
        if (oldPattern == null || newPattern == null)
            return inString;
        StringBuffer sbuf = new StringBuffer();
        int pos = 0;
        int index = inString.indexOf(oldPattern);
        int patLen = oldPattern.length();
        for (; index >= 0; index = inString.indexOf(oldPattern, pos))
        {
            sbuf.append(inString, pos, index);
            sbuf.append(newPattern);
            pos = index + patLen;
        }

        sbuf.append(inString.substring(pos));
        return sbuf.toString();
    }

    public static String getFileSuffix(String filename)
    {
        if (filename == null)
            return null;
        if (filename.lastIndexOf(".") == -1 || filename.lastIndexOf('.') == filename.length() - 1)
            return "";
        StringTokenizer token = new StringTokenizer(filename, ".");
        String filetype;
        for (filetype = ""; token.hasMoreTokens(); filetype = token.nextToken());
        return filetype;
    }

    public static Boolean judgeSuffix(String suffix)
    {
        if (suffix == null)
            return null;
        Set suffixSet = new HashSet();
        suffixSet.add("bat");
        suffixSet.add("cmd");
        suffixSet.add("exe");
        if (suffixSet.contains(suffix))
            return Boolean.valueOf(true);
        else
            return Boolean.valueOf(false);
    }

    public static final String toChinese(String strVal)
    {
        if (strVal == null)
            return null;
        try {
            strVal = new String(strVal.getBytes("ISO8859_1"), "GB2312");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return strVal;

    }

    public static String iptoStr(String ip)
            throws Exception
    {
        String ip_tmp = "";
        StringTokenizer tokenizer = new StringTokenizer(ip, ".");
        String token_tmp = "";
        try
        {
            while (tokenizer.hasMoreTokens())
            {
                token_tmp = tokenizer.nextToken();
                if (token_tmp.length() == 3)
                    ip_tmp = (new StringBuilder(ip_tmp)).append(token_tmp).toString();
                if (token_tmp.length() == 2)
                    ip_tmp = (new StringBuilder(ip_tmp)).append("0").append(token_tmp).toString();
                if (token_tmp.length() == 1)
                    ip_tmp = (new StringBuilder(ip_tmp)).append("00").append(token_tmp).toString();
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
        return ip_tmp;
    }

    public static String getShortLinkTitle(String title, int shortStrLength)
    {
        String tail = "...";
        if (title.length() < shortStrLength + tail.length())
            return title;
        else
            return (new StringBuilder(title.substring(0, shortStrLength))).append(tail).toString();
    }

    public static String[] tokenizeToStringArray(String s, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringTokenizer st = new StringTokenizer(s, delimiters);
        List tokens = new ArrayList();
        while (st.hasMoreTokens())
        {
            String token = st.nextToken();
            if (trimTokens)
                token = token.trim();
            if (!ignoreEmptyTokens || token.length() != 0)
                tokens.add(token);
        }
        return (String[])tokens.toArray(new String[tokens.size()]);
    }

    public static Long[] tokenizeToLongArray(String s, String delimiters)
    {
        if (s == null)
            return null;
        StringTokenizer st = new StringTokenizer(s, delimiters);
        List tokens = new ArrayList();
        while (st.hasMoreTokens())
        {
            String token = st.nextToken();
            token = token.trim();
            if (isNumberStr(token))
                tokens.add(Long.valueOf(token));
        }
        return (Long[])tokens.toArray(new Long[tokens.size()]);
    }

    public static String tokenizeListToString(List input, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringBuffer result = new StringBuffer();
        result.append("(");
        for (Iterator inputIt = input.iterator(); inputIt.hasNext();)
        {
            Object o = inputIt.next();
            if (o != null)
            {
                String token = o.toString();
                if (trimTokens)
                    token = token.trim();
                if (!ignoreEmptyTokens || token.length() != 0)
                {
                    result.append(token);
                    result.append(delimiters);
                }
            }
        }

        result.replace(result.length() - 1, result.length(), ")");
        return result.toString();
    }

    public static String tokenizeListToStringWithNoBracket(List input, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
    {
        StringBuffer result = new StringBuffer();
        for (Iterator inputIt = input.iterator(); inputIt.hasNext();)
        {
            String token = inputIt.next().toString();
            if (trimTokens)
                token = token.trim();
            if (!ignoreEmptyTokens || token.length() != 0)
            {
                result.append(token);
                result.append(delimiters);
            }
        }

        result.replace(result.length() - 1, result.length(), "");
        return result.toString();
    }

    public static String checkString(String inputString)
    {
        if (inputString == null)
            return null;
        String model = "[\\x01-\\x1f]";
        Pattern p = Pattern.compile(model);
        Matcher m = p.matcher(inputString);
        StringBuffer sb = new StringBuffer();
        boolean result = m.find();
        boolean deletedIllegalChars = false;
        for (; result; result = m.find())
        {
            deletedIllegalChars = true;
            m.appendReplacement(sb, "");
            System.out.println((new StringBuilder("�޸�����: ")).append(sb.toString()).toString());
        }

        m.appendTail(sb);
        return sb.toString();
    }

    public static boolean isNumber(String inputString)
    {
        try
        {
            new Double(inputString);
        }
        catch (Exception e)
        {
            return false;
        }
        return true;
    }

    public static Long parseLong(String inputString)
    {
        if (isNumber(inputString))
            return new Long((new Double(inputString)).longValue());
        else
            return null;
    }

    public static Long toLong(String inputString)
    {
        if (isNumber(inputString))
            return new Long((new Double(inputString)).longValue());
        else
            return null;
    }

    public static String longToString(Long input)
    {
        String base = "0000000000";
        if (input == null)
        {
            return base;
        } else
        {
            String in = input.toString();
            in = (new StringBuilder(base)).append(in).toString();
            int len = in.length();
            return in.substring(len - 10, len);
        }
    }

    public static Integer parseInteger(String inputString)
    {
        if (isNumber(inputString))
            return new Integer((new Double(inputString)).intValue());
        else
            return null;
    }

    public static Integer parseInteger(Number inputNum)
    {
        if (inputNum != null)
            return new Integer(inputNum.intValue());
        else
            return null;
    }

    public static Integer toInteger(String inputString)
    {
        if (isNumber(inputString))
            return new Integer((new Double(inputString)).intValue());
        else
            return null;
    }

    public static Integer parseInt(String inputString)
    {
        return parseInteger(inputString);
    }

    public static boolean isAllEqual(List objectList)
    {
        Iterator it = objectList.iterator();
        Object temp = it.next();
        while (it.hasNext())
        {
            Object ob = it.next();
            if (!temp.equals(ob))
                return false;
        }
        return true;
    }

    public static long getMaxLong(List objectList)
    {
        Iterator it = objectList.iterator();
        long temp = ((Long)it.next()).longValue();
        while (it.hasNext())
        {
            long ob = ((Long)it.next()).longValue();
            if (ob > temp)
                temp = ob;
        }
        return temp;
    }

    public static String encodeGBK(String input)
            throws UnsupportedEncodingException
    {
        String output = input;
        if (!System.getProperty("file.encoding").equals("GBK"))
            output = new String(input.getBytes("ISO8859_1"), "GBK");
        return output;
    }

    public static String encodeISO(String input)
            throws UnsupportedEncodingException
    {
        String output = input;
        if (!System.getProperty("file.encoding").equals("GBK"))
            output = new String(input.getBytes("GBK"), "ISO8859_1");
        return output;
    }

    public static boolean isLiteralAndNum(String str)
    {
        if (str == null)
        {
            return false;
        } else
        {
            String model = "[a-zA-Z0-9]*";
            Pattern p = Pattern.compile(model);
            Matcher m = p.matcher(str);
            return m.matches();
        }
    }

    public static String decodeSqlMatching(String matching)
    {
        String retStr = null;
        retStr = replace(matching, "%", "\\%");
        retStr = replace(retStr, "_", "\\_");
        return retStr;
    }

    public static List formateUrl(String url)
    {
        List resultList = new ArrayList();
        String tmpUrl = url;
        String flageHead1 = "http://";
        String flageHead2 = "www.";
        String centUrl = "";
        String urlWithHead1 = "";
        String urlWithHead2 = "";
        String urlWithHead12 = "";
        if (tmpUrl.indexOf(flageHead1) == 0)
        {
            if (tmpUrl.indexOf((new StringBuilder(flageHead1)).append(flageHead2).toString()) == 0)
                centUrl = tmpUrl.substring(flageHead1.length() + flageHead2.length());
            else
                centUrl = tmpUrl.substring(flageHead1.length());
        } else
        if (tmpUrl.indexOf(flageHead2) == 0)
            centUrl = tmpUrl.substring(flageHead2.length());
        else
            centUrl = tmpUrl;
        urlWithHead1 = (new StringBuilder(flageHead1)).append(centUrl).toString();
        urlWithHead2 = (new StringBuilder(flageHead2)).append(centUrl).toString();
        urlWithHead12 = (new StringBuilder(flageHead1)).append(flageHead2).append(centUrl).toString();
        resultList.add(urlWithHead12);
        resultList.add(urlWithHead1);
        resultList.add(urlWithHead2);
        resultList.add(centUrl);
        return resultList;
    }

    public static String generatRandomPassword()
    {
        String passed = "";
        Random random = new Random();
        for (int i = 0; i < 2; i++)
        {
            String rand = String.valueOf(random.nextInt(9));
            passed = (new StringBuilder(passed)).append(rand).toString();
        }

        for (int i = 0; i < 2; i++)
        {
            char letter = (char)(random.nextInt(26) + 65);
            String rand = String.valueOf(letter);
            passed = (new StringBuilder(passed)).append(rand).toString();
        }

        for (int i = 0; i < 2; i++)
        {
            char letter = (char)(random.nextInt(26) + 97);
            String rand = String.valueOf(letter);
            passed = (new StringBuilder(passed)).append(rand).toString();
        }

        return passed;
    }

    public static String filterHTML(String src)
    {
        return src.replaceAll("<.+?>", "");
    }

    public static String filterHTML(String src, int maxLength)
    {
        int endingPos;
        label0:
        {
            if (src == null)
                return null;
            if (maxLength <= 0)
                return "";
            src = Pattern.compile("<[^(<|>)]*>").matcher(src).replaceAll("");
            Matcher matcher = Pattern.compile("&[^(&|;)]+;").matcher(src);
            maxLength = maxLength <= src.length() ? maxLength : src.length();
            endingPos = 0;
            int groupLengthSum = 0;
            int groupCount = 0;
            do
            {
                int nextComparingPos = matcher.find() ? matcher.start() : src.length();
                int transfferedLength = (nextComparingPos - groupLengthSum) + groupCount;
                if (transfferedLength >= maxLength)
                {
                    endingPos = nextComparingPos - (transfferedLength - maxLength);
                    break label0;
                }
                if (matcher.hitEnd())
                    break;
                groupLengthSum += matcher.group().length();
                groupCount++;
            } while (true);
            endingPos = src.length();
        }
        return src.substring(0, endingPos);
    }

    public static String trimString(String src)
    {
        return src != null ? src.trim() : "";
    }

    public static Double parseDouble(String inputString)
    {
        if (isNumber(inputString))
            return Double.valueOf(inputString);
        else
            return null;
    }

    public static Double toDouble(String inputString)
    {
        if (isNumber(inputString))
            return Double.valueOf(inputString);
        else
            return null;
    }

    public static Float parseFloat(String inputString)
    {
        if (isNumber(inputString))
            return Float.valueOf(inputString);
        else
            return null;
    }

    public static Float toFloat(String inputString)
    {
        if (isNumber(inputString))
            return Float.valueOf(inputString);
        else
            return null;
    }

    public static String changeLinedText(String str)
    {
        String ss = str;
        String s1 = "\r\n";
        return ss.replaceAll(s1, "<br>");
    }

    public static boolean isNotEmpty(String target)
    {
        return target != null && !target.trim().equals("");
    }

    public static String createInStr(String str, boolean isChar, String split)
    {
        return createInOrNotinStr(str, "IN", isChar, split);
    }

    public static String createNotInStr(String str, boolean isChar, String split)
    {
        return createInOrNotinStr(str, "NOT IN", isChar, split);
    }

    private static String createInOrNotinStr(String str, String sign, boolean isChar, String split)
    {
        str = str.replaceAll(" ", "");
        str = str.replaceAll("\t", "");
        String s = str;
        if (isChar)
            s = formatString(s, split);
        StringBuilder sb = new StringBuilder(sign);
        sb.append("(");
        if (",".equals(split))
        {
            sb.append(s);
        } else
        {
            String[] temp = s.split(split);
            s = objArrToStr(temp);
            sb.append(s);
        }
        sb.append(")");
        return sb.toString();
    }

    public static String formatString(String target, String split)
    {
        if (target == null || target.length() == 0)
            return null;
        StringBuffer sb = new StringBuffer();
        String[] temp = target.split(split);
        for (int i = 0; i < temp.length; i++)
        {
            sb.append("'");
            sb.append(temp[i]);
            sb.append("'");
            sb.append(",");
        }

        trimEndSeparate(sb, ",");
        return sb.toString();
    }

    public static String objArrToStr(Object[] arr)
    {
        if (arr == null || arr.length <= 0)
            return null;
        else
            return objArrToStr(arr, ",");
    }

    public static String objArrToStr(Object[] arr, String split)
    {
        if (arr == null || arr.length <= 0)
            return null;
        if (split == null)
            split = ",";
        String temp = Arrays.toString(arr);
        temp = temp.replaceAll(", ", split);
        return temp.substring(1, temp.length() - 1);
    }

    public static void trimEndSeparate(StringBuffer str, String separate)
    {
        if (str == null || separate == null || str.length() == 0 || separate.length() == 0)
            return;
        if (str.length() >= separate.length())
            str.setLength(str.length() - separate.length());
    }

    public static boolean checkKeyWords(String keywords)
    {
        if (!isNotEmpty(keywords))
            return false;
        return !keywords.replaceAll(",", "").trim().equals("");
    }

    public static String transferToDBC(String inStr)
            throws UnsupportedEncodingException
    {
        StringBuffer result = new StringBuffer();
        String tempStr = "";
        byte[] b = null;
        String codeType = "unicode";
        if (inStr != null && inStr.length() > 0)
        {
            for (int i = 0; i < inStr.length(); i++)
            {
                tempStr = inStr.substring(i, i + 1);
                b = tempStr.getBytes(codeType);
                if (b != null)
                    if (b[3] == -1)
                    {
                        b[2] = (byte)(b[2] + 32);
                        b[3] = 0;
                        result.append(new String(b, codeType));
                    } else
                    {
                        result.append(tempStr);
                    }
            }

        }
        return result.toString();
    }

    public static String formatKeyWords(String keywords)
            throws UnsupportedEncodingException
    {
        String keywordstr = transferToDBC(keywords);
        Set keywordSet = new TreeSet(Arrays.asList(keywordstr.split(",")));
        keywordstr = tokenizeStringToString((String[])keywordSet.toArray(new String[0]), ",", false, false);
        return keywordstr;
    }

    public static String getFilename(String filepath)
    {
        String filename = null;
        if (filepath == null || filepath.trim().equals(""))
            return "";
        if (filepath.lastIndexOf(File.separator) != -1)
        {
            filename = filepath.substring(filepath.lastIndexOf(File.separator) + 1);
            return filename;
        } else
        {
            return filename;
        }
    }

    public static boolean isNumberStr(String str)
    {
        if (str == null || str.trim().equals(""))
            return false;
        String numstr = "0789";
        char[] strchars = str.toCharArray();
        for (int i = 0; i < strchars.length; i++)
            if (numstr.indexOf(strchars[i]) == -1)
                return false;

        return true;
    }

    public static boolean isPositiveInteger(String str)
    {
        if (str == null)
            return false;
        String regExp = "^[0-9]*[1-9][0-9]*$";
        Pattern p1 = Pattern.compile(regExp);
        Matcher m1 = p1.matcher(str);
        return m1.matches();
    }

    public static boolean equals(String str1, String delim1, String str2, String delim2)
    {
        if (str1 == null || str2 == null)
            return false;
        if (delim1 == null || delim2 == null)
            throw new IllegalArgumentException("ָ���ָ����Ϊ��");
        boolean pass = false;
        StringTokenizer answertokenizer = new StringTokenizer(str1, delim1);
        StringTokenizer usranstokenizer = new StringTokenizer(str2, delim2);
        int anscount = answertokenizer.countTokens();
        if (anscount == usranstokenizer.countTokens())
        {
            int i = 0;
            String[] answers = new String[anscount];
            while (answertokenizer.hasMoreTokens())
                answers[i++] = answertokenizer.nextToken();
            String token = null;
            while (usranstokenizer.hasMoreTokens())
            {
                pass = false;
                token = usranstokenizer.nextToken();
                for (i = 0; i < anscount; i++)
                {
                    if (!token.equals(answers[i]))
                        continue;
                    pass = true;
                    break;
                }

                if (!pass)
                    break;
            }
        }
        return pass;
    }

    public static String[] getNonNullStringArray(String[] strs)
    {
        if (strs == null)
            return null;
        List strList = new ArrayList();
        String[] as;
        int j = (as = strs).length;
        for (int i = 0; i < j; i++)
        {
            String str = as[i];
            if (str != null && !str.equals(""))
                strList.add(str);
        }

        if (strList.size() == 0)
            return null;
        else
            return (String[])strList.toArray(new String[0]);
    }

    public static boolean inStringArray(String[] arg0, String arg1)
    {
        if (arg0 == null || arg0.length == 0 || arg1 == null)
            return false;
        String[] as;
        int j = (as = arg0).length;
        for (int i = 0; i < j; i++)
        {
            String str = as[i];
            if (arg1.equals(str))
                return true;
        }

        return false;
    }

    public static String escapeHTML(String html)
    {
        if (html == null)
            return "";
        else
            return StringEscapeUtils.escapeHtml(html);
    }

    public static String escapeHTML(Number html)
    {
        if (html != null)
            return html.toString();
        else
            return null;
    }

    public static String wipeHTML(String html)
    {
        if (html == null)
            return "";
        else
            return html.replaceAll("<[^>]*>|<[^>]*/>|</[^>]*>", "");
    }

    public static String getSetterName(String fieldName)
    {
        String first = fieldName.substring(0, 1);
        return (new StringBuilder("set")).append(first.toUpperCase()).append(fieldName.substring(1)).toString();
    }

    public static String getGetterName(String fieldName)
    {
        String first = fieldName.substring(0, 1);
        return (new StringBuilder("get")).append(first.toUpperCase()).append(fieldName.substring(1)).toString();
    }

    public static boolean isNull(String str)
    {
        return str == null || str.trim().equals("");
    }

    public static boolean isDate(String str)
    {
        if (isNull(str))
            return false;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setLenient(true);
        try
        {
            df.parse(str);
        }
        catch (ParseException e)
        {
            return false;
        }
        return true;
    }

    public static Date getDate(String str) throws ParseException
    {
        DateFormat df;
        if (isNull(str))
            return null;
        df = new SimpleDateFormat("yyyy-MM-dd");
        df.setLenient(true);
        return df.parse(str);

    }

    public static Date getNextDate(String str)
    {
        DateFormat df;
        if (isNull(str))
            return null;
        df = new SimpleDateFormat("yyyy-MM-dd");
        df.setLenient(true);
        try {
            df.parse(str);
        } catch (ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        df.getCalendar().add(5, 1);
        return df.getCalendar().getTime();
    }

    public static boolean isEmail(String email)
    {
        if (isNull(email))
            return false;
        email = email.trim();
        String expression = "\\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b";
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    public static List getNonNullStringList(List strs)
    {
        if (strs == null)
            return null;
        List strList = new ArrayList();
        for (int i = 0; i < strs.size(); i++)
        {
            String str = (String)strs.get(i);
            if (str != null && !str.equals(""))
                strList.add(str);
        }

        if (strList.size() == 0)
            return null;
        else
            return strList;
    }

    public static String escapeAttr(Object data)
    {
        if (data == null || data.toString() == "null")
            return "";
        else
            return data.toString().replace("&", "&#38;").replace("\"", "&#34;").replace("'", "&#39;");
    }

    public static String escapeJS(Object data)
    {
        if (data == null || data.toString() == "null")
            return "";
        else
            return StringEscapeUtils.escapeJavaScript(data.toString());
    }

    public static String escapeHTML(Object data)
    {
        if (data == null || data.toString() == "null")
            return "";
        else
            return StringEscapeUtils.escapeHtml(data.toString());
    }

    public static boolean isNegative(String str)
    {
        if (isNumber(str))
        {
            double d = Double.parseDouble(str);
            return d < 0.0D;
        } else
        {
            return false;
        }
    }

    public static boolean isPositiveLong(String str)
    {
        if (isLong(str))
        {
            Long d = Long.valueOf(Long.parseLong(str));
            return d.longValue() >= 0L;
        } else
        {
            return false;
        }
    }

    public static boolean isLong(String str)
    {
        if (isNull(str))
            return false;
        try
        {
            Long.parseLong(str);
        }
        catch (NumberFormatException e)
        {
            return false;
        }
        return true;
    }

    public static String nvl(Object obj)
    {
        if (obj == null)
            return "";
        else
            return String.valueOf(obj);
    }

    public static String replace(String str)
    {
        if (str == null || str.trim().equals(""))
            return str;
        if (str.startsWith("["))
            str = str.substring(1);
        if (str.endsWith("]"))
            str = str.substring(0, str.length() - 1);
        if (str.startsWith(","))
            str = str.substring(1);
        if (str.endsWith(","))
            str = str.substring(0, str.length() - 1);
        return str;
    }
    /**
     * 是否中文
     * @param str
     * @return
     */
    public static boolean isChinese(String str){
        if (isNull(str))
            return false;

        if(str.getBytes(StandardCharsets.UTF_8).length != str.length()*3){
            return false;
        }
        return true;

    }
    /**
     * 是否字母
     * @param str
     * @return
     */
    public static boolean isEnglish(String str){
        if (isNull(str))
            return false;
        String lowString=str.toLowerCase();
        char c;
        for (int i = str.length() - 1; i >= 0; i--) {
            c = str.charAt(i);
            if(c<'a' || c>'z'){
                return false;
            }
        }
        return true;
    }
    /**
     * Desc: 转换字符串至长整型值,字符串无效或转换失败返回0L
     *
     * @param str 转换的字符串
     * @return value 转换后的长整型值
     */
    public static long str2long(String str) {
        long value = 0L;

        if (null == str || str.equals("")) { return value; }

        try {
            value = Long.parseLong(str);
        }
        catch (NumberFormatException e) {

        }

        return value;
    }
}
